$pf-c-drawer--breakpoint-map: build-breakpoint-map("base", "lg", "xl", "2xl");
$pf-c-drawer--breakpoint-map--width: build-breakpoint-map("base", "lg", "xl", "2xl");
$pf-c-drawer__panel--list--width: (25, 33, 50, 66, 75, 100);

.pf-c-drawer {
  // Section
  --pf-c-drawer__section--BackgroundColor: var(--pf-global--BackgroundColor--100);

  // Content
  --pf-c-drawer__content--FlexBasis: 100%;
  --pf-c-drawer__content--BackgroundColor: var(--pf-global--BackgroundColor--100);
  --pf-c-drawer__content--ZIndex: var(--pf-global--ZIndex--xs);

  // Panel
  --pf-c-drawer__panel--FlexBasis: 100%;
  --pf-c-drawer__panel--md--FlexBasis: 50%;
  --pf-c-drawer__panel--MinWidth: 50%; // change to __panel--md--MinWidth at breaking change
  --pf-c-drawer__panel--MaxHeight: auto;
  --pf-c-drawer--m-panel-bottom__panel--md--MinHeight: 50%;
  --pf-c-drawer__panel--xl--MinWidth: #{pf-size-prem(450px)};
  --pf-c-drawer__panel--xl--FlexBasis: #{pf-size-prem(450px)};
  --pf-c-drawer--m-panel-bottom__panel--xl--MinHeight: #{pf-size-prem(300px)};
  --pf-c-drawer--m-panel-bottom__panel--xl--FlexBasis: #{pf-size-prem(300px)};
  --pf-c-drawer__panel--ZIndex: var(--pf-global--ZIndex--sm);
  --pf-c-drawer__panel--BackgroundColor: var(--pf-global--BackgroundColor--100);
  --pf-c-drawer__panel--TransitionDuration: var(--pf-global--TransitionDuration);
  --pf-c-drawer__panel--TransitionProperty: margin, transform, box-shadow;

  // Child padding
  --pf-c-drawer--child--PaddingTop: var(--pf-global--spacer--md);
  --pf-c-drawer--child--PaddingRight: var(--pf-global--spacer--md);
  --pf-c-drawer--child--PaddingBottom: var(--pf-global--spacer--md);
  --pf-c-drawer--child--PaddingLeft: var(--pf-global--spacer--md);

  // Responsive child padding
  --pf-c-drawer--child--md--PaddingTop: var(--pf-global--spacer--lg);
  --pf-c-drawer--child--md--PaddingRight: var(--pf-global--spacer--lg);
  --pf-c-drawer--child--md--PaddingBottom: var(--pf-global--spacer--lg);
  --pf-c-drawer--child--md--PaddingLeft: var(--pf-global--spacer--lg);

  // Modified padding, child padding
  --pf-c-drawer--child--m-padding--PaddingTop: var(--pf-global--spacer--md);
  --pf-c-drawer--child--m-padding--PaddingRight: var(--pf-global--spacer--md);
  --pf-c-drawer--child--m-padding--PaddingBottom: var(--pf-global--spacer--md);
  --pf-c-drawer--child--m-padding--PaddingLeft: var(--pf-global--spacer--md);

  // Responsive, modified padding, child padding
  --pf-c-drawer--child--m-padding--md--PaddingTop: var(--pf-global--spacer--lg);
  --pf-c-drawer--child--m-padding--md--PaddingRight: var(--pf-global--spacer--lg);
  --pf-c-drawer--child--m-padding--md--PaddingBottom: var(--pf-global--spacer--lg);
  --pf-c-drawer--child--m-padding--md--PaddingLeft: var(--pf-global--spacer--lg);

  // Content
  --pf-c-drawer__content--child--PaddingTop: 0;
  --pf-c-drawer__content--child--PaddingRight: 0;
  --pf-c-drawer__content--child--PaddingBottom: 0;
  --pf-c-drawer__content--child--PaddingLeft: 0;

  @media screen and (min-width: $pf-global--breakpoint--md) {
    --pf-c-drawer__panel--FlexBasis: var(--pf-c-drawer__panel--md--FlexBasis);

    // Responsive child padding
    --pf-c-drawer--child--PaddingTop: var(--pf-c-drawer--child--md--PaddingTop);
    --pf-c-drawer--child--PaddingRight: var(--pf-c-drawer--child--md--PaddingRight);
    --pf-c-drawer--child--PaddingBottom: var(--pf-c-drawer--child--md--PaddingBottom);
    --pf-c-drawer--child--PaddingLeft: var(--pf-c-drawer--child--md--PaddingLeft);

    // Responsive, modified padding, child padding
    --pf-c-drawer--child--m-padding--PaddingTop: var(--pf-c-drawer--child--m-padding--md--PaddingTop);
    --pf-c-drawer--child--m-padding--PaddingRight: var(--pf-c-drawer--child--m-padding--md--PaddingRight);
    --pf-c-drawer--child--m-padding--PaddingBottom: var(--pf-c-drawer--child--m-padding--md--PaddingBottom);
    --pf-c-drawer--child--m-padding--PaddingLeft: var(--pf-c-drawer--child--m-padding--md--PaddingLeft);
  }

  @media screen and (min-width: $pf-global--breakpoint--xl) {
    --pf-c-drawer__panel--FlexBasis: var(--pf-c-drawer__panel--xl--FlexBasis);
    --pf-c-drawer__panel--MinWidth: var(--pf-c-drawer__panel--xl--MinWidth);

    &.pf-m-panel-bottom {
      --pf-c-drawer__panel--MinWidth: auto;
      --pf-c-drawer__panel--FlexBasis: var(--pf-c-drawer--m-panel-bottom__panel--xl--FlexBasis);
      --pf-c-drawer__panel--MinHeight: var(--pf-c-drawer--m-panel-bottom__panel--xl--MinHeight);
    }
  }

  // Actions
  --pf-c-drawer__actions--MarginTop: calc(var(pf-global--spacer--form-element) * -1);
  --pf-c-drawer__actions--MarginRight: calc(var(pf-global--spacer--form-element) * -1);

  // Box shadow
  --pf-c-drawer__panel--BoxShadow: none;
  --pf-c-drawer--m-expanded__panel--BoxShadow: var(--pf-global--BoxShadow--lg-left);
  --pf-c-drawer--m-expanded--m-panel-left__panel--BoxShadow: var(--pf-global--BoxShadow--lg-right);
  --pf-c-drawer--m-expanded--m-panel-bottom__panel--BoxShadow: var(--pf-global--BoxShadow--lg-top);

  // Divider
  --pf-c-drawer__panel--after--Width: var(--pf-global--BorderWidth--sm);
  --pf-c-drawer--m-panel-bottom__panel--after--Height: var(--pf-global--BorderWidth--sm);
  --pf-c-drawer__panel--after--BackgroundColor: transparent;
  --pf-c-drawer--m-inline--m-expanded__panel--after--BackgroundColor: var(--pf-global--BorderColor--100);
  --pf-c-drawer--m-inline__panel--PaddingLeft: var(--pf-c-drawer__panel--after--Width);
  --pf-c-drawer--m-panel-left--m-inline__panel--PaddingRight: var(--pf-c-drawer__panel--after--Width);
  --pf-c-drawer--m-panel-bottom--m-inline__panel--PaddingTop: var(--pf-c-drawer__panel--after--Width);

  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-x: hidden;

  &.pf-m-inline,
  &.pf-m-static {
    > .pf-c-drawer__main > .pf-c-drawer__panel:not(.pf-m-no-border) {
      padding-left: var(--pf-c-drawer--m-inline__panel--PaddingLeft);
    }
  }

  &.pf-m-panel-left > .pf-c-drawer__main {
    > .pf-c-drawer__panel {
      order: 0;
      margin-right: calc(var(--pf-c-drawer__panel--FlexBasis) * -1);
      transform: translateX(-100%);
    }

    > .pf-c-drawer__content {
      order: 1;
    }
  }

  &.pf-m-panel-bottom > .pf-c-drawer__main {
    flex-direction: column;
  }

  // Expanded
  // stylelint-disable selector-max-class
  &.pf-m-expanded {
    > .pf-c-drawer__main > .pf-c-drawer__panel {
      transform: translateX(-100%);
    }

    &.pf-m-panel-left > .pf-c-drawer__main > .pf-c-drawer__panel {
      transform: translateX(0);
    }

    &.pf-m-panel-bottom > .pf-c-drawer__main > .pf-c-drawer__panel {
      transform: translate(0, -100%);
    }
  }
  // stylelint-enable
}

// Header area
.pf-c-drawer__section {
  flex-grow: 0;
  background-color: var(--pf-c-drawer__section--BackgroundColor);

  &.pf-m-no-background {
    background-color: transparent;
  }
}

// Main area
.pf-c-drawer__main {
  display: flex;
  flex-grow: 1;
  overflow: hidden;
}

// Content / panel
.pf-c-drawer__content,
.pf-c-drawer__panel {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: auto;
}

// Content
.pf-c-drawer__content {
  > .pf-c-drawer__body {
    padding: var(--pf-c-drawer__content--child--PaddingTop) var(--pf-c-drawer__content--child--PaddingRight) var(--pf-c-drawer__content--child--PaddingBottom) var(--pf-c-drawer__content--child--PaddingLeft);
  }

  z-index: var(--pf-c-drawer__content--ZIndex);
  flex-basis: var(--pf-c-drawer__content--FlexBasis);
  order: 0;
  background-color: var(--pf-c-drawer__content--BackgroundColor);

  &.pf-m-no-background {
    background-color: transparent;
  }
}

// Panel
.pf-c-drawer__panel {
  position: relative;
  z-index: var(--pf-c-drawer__panel--ZIndex);
  flex-basis: var(--pf-c-drawer__panel--FlexBasis);
  order: 1;
  max-height: var(--pf-c-drawer__panel--MaxHeight);
  overflow: auto;
  background-color: var(--pf-c-drawer__panel--BackgroundColor);
  box-shadow: var(--pf-c-drawer__panel--BoxShadow);
  transition-duration: var(--pf-c-drawer__panel--TransitionDuration);
  transition-property: var(--pf-c-drawer__panel--TransitionProperty);
  -webkit-overflow-scrolling: touch;

  &::after {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--pf-c-drawer__panel--after--Width);
    height: 100%;
    content: "";
    background-color: var(--pf-c-drawer__panel--after--BackgroundColor);
  }

  &.pf-m-no-background {
    background-color: transparent;
  }
}

// Remove tab focus
@include pf-animate-remove-tab-focus(".pf-c-drawer__panel", var(--pf-c-drawer__panel--TransitionDuration));

// Panel head
.pf-c-drawer__head {
  display: grid;
  grid-template-columns: auto;
  grid-auto-columns: max-content;

  > * {
    grid-column: 1;
  }
}

// Panel actions
.pf-c-drawer__actions {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-self: baseline;
  margin-top: var(--pf-c-drawer__actions--MarginTop);
  margin-right: var(--pf-c-drawer__actions--MarginRight);
}

// Modified content children
.pf-c-drawer__body {
  min-height: 0;
  padding: var(--pf-c-drawer--child--PaddingTop) var(--pf-c-drawer--child--PaddingRight) var(--pf-c-drawer--child--PaddingBottom) var(--pf-c-drawer--child--PaddingLeft);

  // No padding
  &.pf-m-no-padding {
    padding: 0;

    > .pf-c-drawer__actions,
    > .pf-c-drawer__head > .pf-c-drawer__actions {
      margin-top: 0;
      margin-right: 0;
    }
  }

  // Padding
  &.pf-m-padding {
    padding: var(--pf-c-drawer--child--m-padding--PaddingTop) var(--pf-c-drawer--child--m-padding--PaddingRight) var(--pf-c-drawer--child--m-padding--PaddingBottom) var(--pf-c-drawer--child--m-padding--PaddingLeft);
  }

  &:not(.pf-m-no-padding) + * {
    padding-top: 0;
  }

  &:last-child {
    flex: 1 1;
  }
}

// Page level drawer
.pf-c-drawer__body > .pf-c-page__main {
  min-height: 100%;
}

// Layout modifications happen after md breakpoint
@media screen and (min-width: $pf-global--breakpoint--md) {
  // Default
  .pf-c-drawer {
    min-width: var(--pf-c-drawer__panel--MinWidth);

    // stylelint-disable selector-max-class
    // Expanded
    &.pf-m-expanded > .pf-c-drawer__main {
      > .pf-c-drawer__panel {
        box-shadow: var(--pf-c-drawer--m-expanded__panel--BoxShadow);
      }
    }
  }

  // Panel left
  .pf-c-drawer.pf-m-panel-left {
    --pf-c-drawer--m-expanded__panel--BoxShadow: var(--pf-c-drawer--m-expanded--m-panel-left__panel--BoxShadow);

    &.pf-m-inline,
    &.pf-m-static {
      > .pf-c-drawer__main > .pf-c-drawer__panel:not(.pf-m-no-border) {
        padding-right: var(--pf-c-drawer--m-panel-left--m-inline__panel--PaddingRight);
        padding-left: 0;
      }
    }

    &.pf-m-expanded > .pf-c-drawer__main > .pf-c-drawer__panel {
      transform: translateX(0);
    }

    > .pf-c-drawer__main > .pf-c-drawer__panel::after {
      right: 0;
      left: auto;
    }
  }

  .pf-c-drawer.pf-m-panel-bottom {
    --pf-c-drawer--m-expanded__panel--BoxShadow: var(--pf-c-drawer--m-expanded--m-panel-bottom__panel--BoxShadow);
    --pf-c-drawer__panel--MaxHeight: 100%;

    min-width: auto;
    min-height: var(--pf-c-drawer--m-panel-bottom__panel--md--MinHeight);

    &.pf-m-inline,
    &.pf-m-static {
      > .pf-c-drawer__main > .pf-c-drawer__panel:not(.pf-m-no-border) {
        padding-top: var(--pf-c-drawer--m-panel-bottom--m-inline__panel--PaddingTop);
        padding-left: 0;
      }
    }

    > .pf-c-drawer__main > .pf-c-drawer__panel::after {
      top: 0;
      left: auto;
      width: 100%;
      height: var(--pf-c-drawer--m-panel-bottom__panel--after--Height);
    }
  }

  // Border
  .pf-c-drawer > .pf-c-drawer__main > .pf-c-drawer__panel.pf-m-no-border,
  .pf-c-drawer.pf-m-panel-left > .pf-c-drawer__main > .pf-c-drawer__panel.pf-m-no-border {
    --pf-c-drawer--m-expanded__panel--BoxShadow: none;
  }
  // stylelint-enable
}

// Responsive width modifiers
@each $breakpoint, $breakpoint-value in $pf-c-drawer--breakpoint-map--width {
  $breakpoint-name: if($breakpoint != "base", -on-#{$breakpoint}, "");

  @if $breakpoint == "base" {
    $breakpoint: "md";
  }

  @include pf-apply-breakpoint($breakpoint, $pf-c-drawer--breakpoint-map--width) {
    @each $width-value in $pf-c-drawer__panel--list--width {
      .pf-c-drawer__panel.pf-m-width-#{$width-value}#{$breakpoint-name} {
        --pf-c-drawer__panel--FlexBasis: #{percentage($width-value / 100)};
      }
    }
  }
}

// Responsive modifiers
@each $breakpoint, $breakpoint-value in $pf-c-drawer--breakpoint-map {
  $breakpoint-name: if($breakpoint != "base", -on-#{$breakpoint}, "");

  @if $breakpoint == "base" {
    $breakpoint: "md";
  }

  @include pf-apply-breakpoint($breakpoint, $pf-c-drawer--breakpoint-map) {
    // Drawer and inline
    .pf-c-drawer.pf-m-inline#{$breakpoint-name},
    .pf-c-drawer.pf-m-static#{$breakpoint-name} {
      > .pf-c-drawer__main > .pf-c-drawer__content {
        flex-shrink: 1;
      }

      > .pf-c-drawer__main > .pf-c-drawer__panel {
        --pf-c-drawer--m-expanded__panel--BoxShadow: none;

        &:not(.pf-m-no-border)::after {
          background-color: var(--pf-c-drawer--m-inline--m-expanded__panel--after--BackgroundColor);
        }
      }
    }

    // Drawer inline
    .pf-c-drawer.pf-m-inline#{$breakpoint-name} {
      > .pf-c-drawer__main > .pf-c-drawer__content {
        overflow-x: auto;
      }

      > .pf-c-drawer__main > .pf-c-drawer__panel {
        margin-left: calc(var(--pf-c-drawer__panel--FlexBasis) * -1);
        transform: translateX(100%);
      }

      // stylelint-disable selector-max-class, selector-max-combinators, selector-max-compound-selectors
      // Inline, expanded
      &.pf-m-expanded > .pf-c-drawer__main > .pf-c-drawer__panel {
        margin-left: 0;
        transform: translateX(0);
      }

      > .pf-c-drawer__main > .pf-c-drawer__panel > .pf-c-drawer__body > .pf-c-drawer__head .pf-c-drawer__close {
        display: unset;
        visibility: visible;
      }

      // Panel left
      &.pf-m-panel-left {
        > .pf-c-drawer__main > .pf-c-drawer__panel {
          margin-right: calc(var(--pf-c-drawer__panel--FlexBasis) * -1);
          margin-left: 0;
          transform: translateX(-100%);
        }

        // Inline, expanded, panel left
        &.pf-m-expanded > .pf-c-drawer__main > .pf-c-drawer__panel {
          margin-right: 0;
          transform: translateX(0);
        }

        > .pf-c-drawer__main > .pf-c-drawer__panel > .pf-c-drawer__body > .pf-c-drawer__head .pf-c-drawer__close {
          display: unset;
          visibility: visible;
        }
        // stylelint-enable
      }
    }

    // Static
    .pf-c-drawer.pf-m-static#{$breakpoint-name} {
      > .pf-c-drawer__main > .pf-c-drawer__panel {
        transform: translateX(0);
      }

      // stylelint-disable max-nesting-depth, selector-max-class, selector-max-combinators, selector-max-compound-selectors
      &.pf-m-panel-left {
        > .pf-c-drawer__main > .pf-c-drawer__panel {
          margin-right: 0;
          transform: translateX(0);
        }
      }

      &.pf-m-panel-bottom {
        > .pf-c-drawer__main > .pf-c-drawer__panel {
          transform: translateX(0);
        }
      }

      > .pf-c-drawer__main > .pf-c-drawer__panel > .pf-c-drawer__body > .pf-c-drawer__head .pf-c-drawer__close {
        display: none;
        visibility: hidden;
      }
      // stylelint-enable
    }
  }
}
